﻿<cfsilent>
	<cfscript>
		
		dictAdvice = getProperty("serviceFactory").getBean("senateDictionaryAdvice");
		markAdvice = getProperty("serviceFactory").getBean("markAdvice");
		
		sessionAdvice = getProperty("serviceFactory").getBean("sessionAdvice");
		depId = sessionAdvice.getUserProp("teacherDepartment");
		
		studentId = event.getArg('STU');
		classId = event.getArg('CLS');
		
		/* 读取学生信息 */
		sql = "SELECT 
					a.stu_name, b.cls_id, b.cls_name 
				FROM t_student a 
				INNER JOIN t_class b ON b.cls_id = a.cls_id 
				WHERE 
					a.stu_id = :studentId ";
		
		queryObj = new Query( datasource=application.dnsSlave ) ;
   		queryObj.addParam( name="studentId", value=studentId, cfsqltype="cf_sql_varchar" );
		
		rs_student = queryObj.execute( sql=sql ).getResult();
		
		
		event.setArg("pageTitle", "教学运行基础数据 - 学生学籍 - 学生成绩明细 - " & rs_student.stu_name);
		
		passArgs = structNew();
		structInsert(passArgs, "STU", studentId );
		structInsert(passArgs, "Class", rs_student.cls_id );

		/* 计划课程 */
		sql = "SELECT 
				t_term.academic_year, t_term.academic_term, 
				t_course.course_name, t_course.course_credit, 
				t_student_mark.retaking, t_student_mark.mark_mode, t_student_mark.mark_result, t_student_mark.mark_note, 
				t_student_mark.mark_resit, t_student_mark.mark_renote, t_student_mark.mark_resit_limit, 
				t_student_mark.credit_point, 
				t_course_prop.prop_id, t_course_prop.prop_name 
				FROM t_student_mark 
				INNER JOIN t_term ON t_term.term_id = t_student_mark.term_id 
				INNER JOIN t_course ON t_course.cid = t_student_mark.cid 
				INNER JOIN t_course_prop ON t_course_prop.prop_id = t_student_mark.prop_id 
				WHERE 
					t_student_mark.stu_id = :studentId 
					AND 
					t_student_mark.task_type = 'P' 
				ORDER BY 
					t_term.academic_year DESC, t_term.academic_term, t_course_prop.prop_id, t_course.course_name";
		
		queryObj = new Query( datasource=application.dnsSlave );
		queryObj.addParam( name="studentId", value=studentId, cfsqltype="cf_sql_varchar" );
		
		rs_plan = queryObj.execute( sql=sql ).getResult();


		termYearArray = [];
		termArray = [];
		
		if ( rs_plan.recordCount ) { 
			
			for( j=1; j LTE rs_plan.recordCount; j++ ){
				termYear = [ rs_plan["academic_year"][j], 0 ];
				if ( not arrayFind( termYearArray, termYear ) ) {
					arrayAppend( termYearArray, termYear );
				}
			}

			i=0; 
			for ( termYear in termYearArray ) {
				i++;
				for( j=1; j LTE rs_plan.recordCount; j++ ){
					if ( rs_plan["academic_year"][j] eq termYear[1] ) {

						termYear[2] ++;
						termYearArray[i] = termYear;

					}
				}
			}

			for( j=1; j LTE rs_plan.recordCount; j++ ){
				term = [ rs_plan["academic_year"][j], rs_plan["academic_term"][j], 0 ];
				if ( not arrayFind( termArray, term ) ) {
					arrayAppend( termArray, term );
				}
			}

			i=0;
			for ( term in termArray ) {
				i++;
				for( j=1; j LTE rs_plan.recordCount; j++ ){
					if ( rs_plan["academic_year"][j] eq term[1] and rs_plan["academic_term"][j] eq term[2] ) {
						term[3] = term[3] + 1;
						termArray[i] = term;
					}
				}
			}
			
		}
		
		
		/* 全校通选 */
		sql = "SELECT 
				t_term.academic_year, t_term.academic_term, 
				t_course.course_name, t_course.course_credit, 
				t_student_mark.retaking, t_student_mark.mark_mode, t_student_mark.mark_result, t_student_mark.mark_note, 
				t_student_mark.mark_resit, t_student_mark.mark_renote, t_student_mark.mark_resit_limit, 
				t_course_prop.prop_id, t_course_prop.prop_name 
				FROM t_student_mark 
				INNER JOIN t_term ON t_term.term_id = t_student_mark.term_id 
				INNER JOIN t_course ON t_course.cid = t_student_mark.cid 
				INNER JOIN t_course_prop ON t_course_prop.prop_id = t_student_mark.prop_id 
				WHERE 
					stu_id = :studentId 
					AND 
					task_type = 'C' 
				ORDER BY 
					t_term.academic_year, t_term.academic_term, t_course_prop.prop_id, t_course.course_name";
		
		queryObj = new Query( datasource=application.dnsSlave );
		queryObj.addParam( name="studentId", value=studentId, cfsqltype="cf_sql_varchar" );
		
		rs_common = queryObj.execute( sql=sql ).getResult();

		/* 体育选项 */
		sql = "SELECT 
				t_term.academic_year, t_term.academic_term, 
				t_course.course_name, t_course.course_credit, 
				t_student_mark.retaking, t_student_mark.mark_mode, t_student_mark.mark_result, t_student_mark.mark_note, 
				t_student_mark.mark_resit, t_student_mark.mark_renote, t_student_mark.mark_resit_limit, 
				t_course_prop.prop_id, t_course_prop.prop_name 
				FROM t_student_mark 
				INNER JOIN t_term ON t_term.term_id = t_student_mark.term_id 
				INNER JOIN t_course ON t_course.cid = t_student_mark.cid 
				INNER JOIN t_course_prop ON t_course_prop.prop_id = t_student_mark.prop_id 
				WHERE 
					stu_id = :studentId 
					AND 
					task_type = 'T' 
				ORDER BY 
					t_term.academic_year, t_term.academic_term, t_course_prop.prop_id, t_course.course_name";
		
		queryObj = new Query( datasource=application.dnsSlave );
		queryObj.addParam( name="studentId", value=studentId, cfsqltype="cf_sql_varchar" );
		
		rs_physical = queryObj.execute( sql=sql ).getResult();
		

		/* 以往四六级考试成绩 */
		sql = "SELECT 
				exam_id, scroll_id, absent, scroll, listening, reading, writing, integration
				FROM t_cet_scroll 
				WHERE 
					stu_id = :studentId 
				ORDER BY 
					scroll_id DESC ";
		
		queryObj = new Query( datasource=application.dnsSlave );
		queryObj.addParam( name="studentId", value=studentId, cfsqltype="cf_sql_varchar" );
		
		rs_cet = queryObj.execute( sql=sql ).getResult();
		
		currentTab = event.getArg("TabID", "labPlan");
		
	</cfscript>
</cfsilent>

<div id="headArea">
	<div class="uiHeader uiHeaderWithImage ptm">
		<div class="clearfix uiHeaderTop">
			<div class="uiHeaderActions rfloat">
				<a class="uiButton" href="<cfoutput>#buildURL('studentMarkByClass', passArgs)#</cfoutput>"><i class="mrs img btnList"></i><span class="uiButtonText"><cfoutput>#rs_student.cls_name#</cfoutput></span></a>
			</div>
			<div>
				<h2 class="uiHeaderTitle">
					<i class="uiHeaderImage img icon16x16 application"></i><cfoutput>#rs_student.stu_name#</cfoutput> 学生成绩档案
				</h2>
			</div>
		</div>
	</div>
</div>

<div class="UIElement">
	<ul class="senateFirstPage">
		<li>
			<div class="clearfix" id="welcome">
				
				<div class="UItab">
					<div class="tabLables">
						<span <cfif currentTab eq "labPlan">class="active"</cfif> id="labPlan" tabTarget="Plan">计划课程</span>
						<span <cfif currentTab eq "labCommon">class="active"</cfif> id="labCommon" tabTarget="Common">全校通选课</span>
						<span <cfif currentTab eq "labPhysical">class="active"</cfif> id="labPhysical" tabTarget="Physical">体育项目</span>
						<span <cfif currentTab eq "labCET">class="active"</cfif> id="labCET" tabTarget="CET">外语等级考试</span>
					</div>
				</div>
				<script language="javascript" type="text/javascript">
					//<![CDATA[
					<!--
					$(document).ready(function() {
						
						/* init Tab */
						$("div.tabContent").hide();
						$("div#" + $("div.tabLables span.active").attr("tabTarget")).show();
						
						$("div.tabLables > span").click(function(){
							var $targetID = $(this).attr("tabTarget");
							
							$("div.tabLables span").removeClass("active");
							$(this).addClass("active");
							
							$("div.tabContent").not('[id="' + $targetID + '"]').hide();
							$("div.tabContent#" + $targetID).show();
						});
						
					});
					
					// -->
					//]]>
				</script>
				
				<div id="Plan" class="tabContent">
				
					<div class="noticeBlock">
						<div class="operation">
							<a class="uiButton uiButtonSpecial" href="<cfoutput>#BuildURL('studentMarkDownloadExcel', passArgs)#</cfoutput>"><i class="mrs img btnDownload"></i><span class="uiButtonText">导出所有成绩</span></a>
							<a class="uiButton" target="_blank" href="<cfoutput>#buildURL('studentMarkPassPrint', passArgs)#</cfoutput>"><i class="mrs img btnPrint"></i><span class="uiButtonText">打印通过课程成绩单</span></a>
							<a class="uiButton" target="_blank" href="<cfoutput>#buildURL('studentMarkPrint', passArgs)#</cfoutput>"><i class="mrs img btnPrint"></i><span class="uiButtonText">打印成绩单</span></a>
						</div>
						<h3>培养方案课程</h3>
						<hr/>
					</div>
					
					<cfif rs_plan.recordCount eq 0>
						<div class="systemNotice">
							<h3><span class="img icon16x16 info"></span>尚无历史成绩</h3>
							<p>当前还没有您修读课程的成绩信息.</p>
						</div>
					</cfif>
					
					<cfif arrayLen(termYearArray)>
						
						<cfloop array="#termYearArray#" index="termYear">
							<table class="UItable">
								<tr class="cellBorder">
									<td colspan="7">
										<span class="number bold"><cfoutput>#termYear[1]#</cfoutput></span> 学年
										共计 <span class="number bold"><cfoutput>#termYear[2]#</cfoutput></span> 门课程
									</td>
								</tr>
								
								<cfloop array="#termArray#" index="term">
									<cfif term[1] eq termYear[1]>
										
										<cfset termMarkCredit = 0 />
										<cfset termCredit = 0 />
										
										<cfset termMarkCreditReq = 0 />
										<cfset termCreditReq = 0 />

										<tr class="cellBorder">
											<td width="10" rowspan="<cfoutput>#(term[3] + 3)#</cfoutput>"><cfoutput>#dictAdvice.getTermName( term[2] )#</cfoutput></td>
										</tr>
										<tr class="cellBorder">
											<td>课程</td>
											<td align="center" width="40">学分</td>
											<td align="center" width="60">课程性质</td>
											<td align="center" width="60">正考</td>
											<td align="center" width="60">补考</td>
											<td align="center" width="80">课程学分绩点</td>
										</tr>

										<cfloop query="rs_plan">
											
											<cfif term[1] eq rs_plan.academic_year and term[2] eq rs_plan.academic_term >
											
												<cfset courseMarkCredit = rs_plan.credit_point />
												
												<cfset termMarkCredit = termMarkCredit + courseMarkCredit />
												<cfset termCredit = termCredit + rs_plan.course_credit />
												
												<cfset finalResult = markAdvice.getMark( rs_plan.mark_mode, rs_plan.mark_result, rs_plan.mark_note ) />
												<cfset resitResult = markAdvice.getMarkResit( rs_plan.mark_mode, rs_plan.mark_resit, rs_plan.mark_renote, rs_plan.mark_resit_limit ) />
												
												<cfif rs_plan.prop_id eq "1">
													<cfset termMarkCreditReq = termMarkCreditReq + courseMarkCredit />
													<cfset termCreditReq = termCreditReq + rs_plan.course_credit />
												</cfif>
												
												<tr class="cellBorder <cfif max(rs_plan.mark_result, rs_plan.mark_resit) lt 60>alertRow</cfif>">
													<td><cfoutput>#rs_plan.course_name#</cfoutput> <cfif rs_plan.retaking>(重新学习)</cfif></td>
													<td align="center"><span class="number"><cfoutput>#numberFormat( rs_plan.course_credit, "_._" )#</cfoutput></span></td>
													<td align="center"><cfoutput>#rs_plan.prop_name#</cfoutput></td>
													<td align="center"><cfif isNumeric(finalResult)><span class="number"><cfoutput>#finalResult#</cfoutput></span><cfelse><cfoutput>#finalResult#</cfoutput></cfif></td>
													<td align="center"><cfif isNumeric(resitResult)><span class="number"><cfoutput>#resitResult#</cfoutput></span><cfelse><cfoutput>#resitResult#</cfoutput></cfif></td>
													<td align="center"><cfif courseMarkCredit gt 0><span class="number"><cfoutput>#numberFormat( courseMarkCredit, "_.__")#</cfoutput></span></cfif></td>
												</tr>
											</cfif>
										</cfloop>
										
										<tr class="cellBorder">
											<td colspan="6" align="right">
												平均学分绩点 <span class="number bold"><cfif termCredit gt 0><cfoutput>#numberFormat( termMarkCredit/termCredit, "_.___")#</cfoutput><cfelse>-/-</cfif></span>
												&nbsp;&nbsp;&nbsp;&nbsp;
												必修课绩点 <span class="number bold"><cfif termCreditReq gt 0><cfoutput>#numberFormat( termMarkCreditReq/termCreditReq, "_.___")#</cfoutput><cfelse>-/-</cfif></span>
											</td>
										</tr>
									</cfif>
								</cfloop>
							</table>
						</cfloop>
						
					</cfif>
					
				</div>
				
				<div id="Common" class="tabContent">
				
					<div class="noticeBlock">
						<h3>全校通选课</h3>
						<hr/>
					</div>
					
					<cfif rs_common.recordCount eq 0>
						<div class="systemNotice">
							<h3><span class="img icon16x16 info"></span>尚无历史成绩</h3>
							<p>当前还没有您修读通选课的成绩信息.</p>
						</div>
					</cfif>
					
					<cfif rs_common.recordCount >
						
						<cfset markDone = 0 />
						
						<table class="UItable">
							<tr class="cellBorder">
								<td width="120">学期</td>
								<td>课程</td>
								<td align="center" width="40">学分</td>
								<td align="center" width="60">正考</td>
								<td align="center" width="60">补考</td>
							</tr>
							<cfloop query="rs_common">
								
								<cfif max( rs_common.mark_result, rs_common.mark_resit ) gte 60 >
									<cfset markDone = markDone + rs_common.course_credit />
								</cfif>
								
								<cfset finalResult = markAdvice.getMark( rs_common.mark_mode, rs_common.mark_result, rs_common.mark_note ) />
								<cfset resitResult = markAdvice.getMarkResit( rs_common.mark_mode, rs_common.mark_resit, rs_common.mark_renote, rs_common.mark_resit_limit ) />

								<tr class="cellBorder <cfif max(rs_common.mark_result, rs_common.mark_resit) lt 60>alertRow</cfif>">
									<td><span class="number bold"><cfoutput>#rs_common.academic_year#</cfoutput>-<cfoutput>#rs_common.academic_term#</cfoutput></span></td>
									<td><cfoutput>#rs_common.course_name#</cfoutput></td>
									<td align="center"><span class="number"><cfoutput>#numberFormat( rs_common.course_credit, "_._" )#</cfoutput></span></td>
									<td align="center"><cfif isNumeric(finalResult)><span class="number"><cfoutput>#finalResult#</cfoutput></span><cfelse><cfoutput>#finalResult#</cfoutput></cfif></td>
									<td align="center"><cfif isNumeric(resitResult)><span class="number"><cfoutput>#resitResult#</cfoutput></span><cfelse><cfoutput>#resitResult#</cfoutput></cfif></td>
								</tr>
							</cfloop>
							<tr class="cellBorder">
								<td colspan="5" align="right">已获得学分 <span class="number bold"><cfoutput>#numberFormat(markDone, "_.__")#</cfoutput></span></td>
							</tr>
						</table>
					
					</cfif>

				</div>
				
				<div id="Physical" class="tabContent">
					
					<div class="noticeBlock">
						<h3>体育项目成绩</h3>
						<hr/>
					</div>
					
					<cfif rs_physical.recordCount eq 0>
						<div class="systemNotice">
							<h3><span class="img icon16x16 info"></span>尚无历史成绩</h3>
							<p>当前还没有您修读体育项目的成绩信息.</p>
						</div>
					</cfif>
					
					<cfif rs_physical.recordCount >
						
						<cfset markDone = 0 />
						
						<table class="UItable">
							<tr class="cellBorder">
								<td width="120">学期</td>
								<td>课程</td>
								<td align="center" width="40">学分</td>
								<td align="center" width="60">正考</td>
								<td align="center" width="60">补考</td>
							</tr>
							<cfloop query="rs_physical">
								
								<cfif max( rs_physical.mark_result, rs_physical.mark_resit ) gte 60 >
									<cfset markDone = markDone + rs_physical.course_credit />
								</cfif>
								
								<cfset finalResult = markAdvice.getMark( rs_physical.mark_mode, rs_physical.mark_result, rs_physical.mark_note ) />
								<cfset resitResult = markAdvice.getMarkResit( rs_physical.mark_mode, rs_physical.mark_resit, rs_physical.mark_renote, rs_physical.mark_resit_limit ) />
								
								<tr class="cellBorder <cfif max(rs_physical.mark_result, rs_physical.mark_resit) lt 60>alertRow</cfif>">
									<td><span class="number bold"><cfoutput>#rs_common.academic_year#</cfoutput>-<cfoutput>#rs_common.academic_term#</cfoutput></span></td>
									<td><cfoutput>#rs_physical.course_name#</cfoutput></td>
									<td align="center"><span class="number"><cfoutput>#numberFormat( rs_physical.course_credit, "_._" )#</cfoutput></span></td>
									<td align="center"><cfif isNumeric(finalResult)><span class="number"><cfoutput>#finalResult#</cfoutput></span><cfelse><cfoutput>#finalResult#</cfoutput></cfif></td>
									<td align="center"><cfif isNumeric(resitResult)><span class="number"><cfoutput>#resitResult#</cfoutput></span><cfelse><cfoutput>#resitResult#</cfoutput></cfif></td>
								</tr>
							</cfloop>
							<tr class="cellBorder">
								<td colspan="5" align="right">已获得学分 <span class="number bold"><cfoutput>#numberFormat(markDone, "_.__")#</cfoutput></span></td>
							</tr>
						</table>
					
					</cfif>
					
				</div>

				<div id="CET" class="tabContent">
				
					<div class="noticeBlock">
						<h3>四六级考试成绩记录</h3>
						<hr/>
					</div>
					
					<cfif rs_cet.recordCount eq 0 >
						<div class="systemNotice">
							<h3><span class="img icon16x16 info"></span>尚无历史成绩</h3>
							<p>当前还没有您的四六级考试成绩信息, 可能考试成绩尚未下发到学校 或 之前您没有报考.</p>
						</div>
					</cfif>
					
					<cfif rs_cet.recordCount >

						<table class="UItable">
							<tr class="cellBorder">
								<td width="180">准考证号</td>
								<td>考试场次</td>
								<td width="60">语言级别</td>
								<td align="center" width="40">总分</td>
								<td align="center" width="40">听力</td>
								<td align="center" width="40">阅读</td>
								<td align="center" width="40">写作</td>
								<td align="center" width="40">综合</td>
							</tr>
							<cfloop query="rs_cet">
								<tr class="cellBorder <cfif rs_cet.scroll lt 425>alertRow</cfif>">
									<td><span class="numeric"><cfoutput>#rs_cet.scroll_id#</cfoutput></span></td>
									<td>20<cfoutput>#mid(rs_cet.scroll_id, 7, 2)#</cfoutput>年 <cfif mid(rs_cet.scroll_id, 9, 1) eq "1">夏季<cfelse>冬季</cfif> 全国大学外语等级考试</td>
									<td><span class="numeric"><cfoutput>#rs_cet.exam_id#</cfoutput></span></td>
									<cfif rs_cet.absent eq "1">
											<td colspan="5" class="alertCell" align="center">缺考</td>
										<cfelse>
											<td align="center"><span class="numeric bold"><cfoutput>#rs_cet.scroll#</cfoutput></span></td>
											<td align="center"><span class="numeric"><cfoutput>#rs_cet.listening#</cfoutput></span></td>
											<td align="center"><span class="numeric"><cfoutput>#rs_cet.reading#</cfoutput></span></td>
											<td align="center"><span class="numeric"><cfoutput>#rs_cet.writing#</cfoutput></span></td>
											<td align="center"><span class="numeric"><cfoutput>#rs_cet.integration#</cfoutput></span></td>
									</cfif>
								</tr>
							</cfloop>
						</table>
						
					</cfif>
					
				</div>

			</div>
		</li>
	</ul>
</div>